package com.example.springboottest.controller;


import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import com.github.xiaoymin.knife4j.annotations.DynamicResponseParameters;
import io.swagger.annotations.*;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *
 * </p>
 *
 * @author gzj
 * @since 2023/8/1
 */
@Api(tags = "测试")
@RestController
@RequestMapping("/hello")
public class Controller {

    @ApiOperation(value = "普通body-Get请求")
    @GetMapping("testGet")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "名称",example = "张飞",dataTypeClass = String.class),
            @ApiImplicitParam(name = "money",value = "金钱",example = "123",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "age",value = "年龄",example = "22",dataTypeClass = Integer.class)
    })
    public String testGet(String name,Long money,Integer age){
        return "name : " + name +", money : " + money + ", age : " + age;
    }

    @PostMapping("testPost")
    @ApiOperation(value = "普通body-Post请求")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "名称",example = "张飞",dataTypeClass = String.class),
            @ApiImplicitParam(name = "money",value = "金钱",example = "123",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "age",value = "年龄",example = "22",dataTypeClass = Integer.class)
    })
    public Results word(@RequestBody Bean bean){
        return Results.builder().code(200).data(bean).build();
    }

}

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel("响应参数")
class Results<T> implements Serializable {
    private static final long serialVersionUID = -8782333365744933352L;
    @ApiModelProperty(value = "code")
    private Integer code;
    @ApiModelProperty(value = "返回值")
    private T data;

}

@ApiModel("响应")
class Bean {
    @ApiModelProperty(value = "名称")
    private String name;
    @ApiModelProperty(value = "金钱")
    private Long money;
    @ApiModelProperty(value = "年龄")

    private Integer age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getMoney() {
        return money;
    }

    public void setMoney(Long money) {
        this.money = money;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "bean{" +
                "name='" + name + '\'' +
                ", money=" + money +
                ", age=" + age +
                '}';
    }
}
